<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
                    xmlns:local="clr-namespace:PropertyTools.Wpf">

  <Style x:Key="ComboBoxFocusVisual">
    <Setter Property="Control.Template">
      <Setter.Value>
        <ControlTemplate>
          <Rectangle Margin="4,4,21,4" StrokeThickness="1"
                     Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeDashArray="1 2" SnapsToDevicePixels="true" />
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <LinearGradientBrush x:Key="ButtonNormalBackground" StartPoint="0,0" EndPoint="0,1">
    <LinearGradientBrush.GradientStops>
      <GradientStop Color="#F3F3F3" Offset="0" />
      <GradientStop Color="#EBEBEB" Offset="0.5" />
      <GradientStop Color="#DDDDDD" Offset="0.5" />
      <GradientStop Color="#CDCDCD" Offset="1" />
    </LinearGradientBrush.GradientStops>
  </LinearGradientBrush>

  <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070" />

  <Geometry x:Key="DownArrowGeometry">
    M 0 0 L 3.5 4 L 7 0 Z
  </Geometry>

  <Style x:Key="ComboBoxReadonlyToggleButton" TargetType="{x:Type ToggleButton}">
    <Setter Property="OverridesDefaultStyle" Value="true" />
    <Setter Property="IsTabStop" Value="false" />
    <Setter Property="Focusable" Value="false" />
    <Setter Property="ClickMode" Value="Press" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ToggleButton}">
          <theme:ButtonChrome Name="Chrome" Background="{TemplateBinding Background}"
                              BorderBrush="{TemplateBinding BorderBrush}" RenderMouseOver="{TemplateBinding IsMouseOver}"
                              RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="true">
            <Grid Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
                  HorizontalAlignment="Right">
              <Path Name="Arrow" Margin="3,1,0,0" Fill="Black" Data="{StaticResource DownArrowGeometry}"
                    HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Grid>
          </theme:ButtonChrome>
          <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="true">
              <Setter TargetName="Chrome" Property="RenderPressed" Value="true" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter TargetName="Arrow" Property="Fill" Value="#AFAFAF" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type local:PopupBox}">
    <Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}" />
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
    <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}" />
    <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
    <Setter Property="Padding" Value="4,3" />
    <!--<Setter Property="ScrollViewer.CanContentScroll"
                Value="true"/>
        <Setter Property="ScrollViewer.PanningMode"
                Value="Both"/>-->
    <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:PopupBox}">


          <Grid Name="MainGrid" SnapsToDevicePixels="true">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*" />
              <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
                                Width="0" />
            </Grid.ColumnDefinitions>
            <Popup Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" Placement="Bottom" Margin="1"
                   IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
              <theme:SystemDropShadowChrome Name="Shdw" Color="Transparent"
                                            MinWidth="{Binding ElementName=MainGrid,Path=ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
                <Border x:Name="DropDownBorder" BorderThickness="1"
                        BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
                        Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
                  <!--<Grid RenderOptions.ClearTypeHint="Enabled">-->
                  <Grid>
                    <!--<Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top">
                                                    <Rectangle 
                                                Name="OpaqueRect"
                                                Height="{Binding ElementName=DropDownBorder,Path=ActualHeight}" 
                                                Width="{Binding ElementName=DropDownBorder,Path=ActualWidth}" 
                                                Fill="{Binding ElementName=DropDownBorder,Path=Background}" />
                                                </Canvas>-->
                    <ContentPresenter Name="HeaderPresenter"
                                      Content="{Binding Mode=OneWay,RelativeSource={RelativeSource TemplatedParent}}"
                                      ContentTemplate="{TemplateBinding PopupTemplate}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                  </Grid>
                </Border>
              </theme:SystemDropShadowChrome>
            </Popup>
            <ToggleButton Grid.ColumnSpan="2" Background="{TemplateBinding Background}"
                          BorderBrush="{TemplateBinding BorderBrush}" Style="{StaticResource ComboBoxReadonlyToggleButton}"
                          IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" />
            <ContentPresenter IsHitTestVisible="false" Margin="{TemplateBinding Padding}"
                              Content="{TemplateBinding SelectedValue}" ContentTemplate="{TemplateBinding ItemTemplate}"
                              ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                              ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
          </Grid>

          <ControlTemplate.Triggers>
            <Trigger SourceName="PART_Popup" Property="Popup.HasDropShadow" Value="true">
              <Setter TargetName="Shdw" Property="Margin" Value="0,0,5,5" />
              <Setter TargetName="Shdw" Property="Color" Value="#71000000" />
            </Trigger>
            <!--<Trigger Property="HasItems"
                                 Value="false">
                            <Setter TargetName="DropDownBorder"
                                    Property="Height"
                                    Value="95"/>
                        </Trigger>-->
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
              <Setter Property="Background" Value="#FFF4F4F4" />
            </Trigger>
            <!--<Trigger Property="IsGrouping"
                                 Value="true">
                            <Setter Property="ScrollViewer.CanContentScroll"
                                    Value="false"/>
                        </Trigger>-->
            <!--<Trigger SourceName="DropDownScrollViewer"
                                 Property="ScrollViewer.CanContentScroll"
                                 Value="false" >
                            <Setter TargetName="OpaqueRect" 
                                    Property="Canvas.Top" 
                                    Value="{Binding ElementName=DropDownScrollViewer, Path=VerticalOffset}" />
                            <Setter TargetName="OpaqueRect" 
                                    Property="Canvas.Left" 
                                    Value="{Binding ElementName=DropDownScrollViewer, Path=HorizontalOffset}" />
                        </Trigger>-->
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <!--<Style.Triggers>
            <Trigger Property="IsEditable"
                     Value="true">
                <Setter Property="BorderBrush"
                        Value="{StaticResource TextBoxBorder}"/>
                <Setter Property="Background"
                        Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
                <Setter Property="IsTabStop"
                        Value="false"/>
                <Setter Property="Padding"
                        Value="3"/>
                <Setter Property="Template"
                        Value="{StaticResource ComboBoxEditableTemplate}"/>
            </Trigger>
        </Style.Triggers>-->
  </Style>

</ResourceDictionary>